package com.ruoyi.web.controller.decision;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.decision.domain.PlanClassification;
import com.ruoyi.decision.service.IPlanClassificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 方案库分类Controller
 * 
 * @author zbw
 * @date 2022-07-20
 */
@RestController
@RequestMapping("/decision/planclassification")
public class PlanClassificationController extends BaseController
{
    @Autowired
    private IPlanClassificationService planClassificationService;

    /**
     * 查询方案库分类列表
     */
    @PreAuthorize("@ss.hasPermi('decision:planclassification:list')")
    @GetMapping("/list")
    public TableDataInfo list(PlanClassification planClassification)
    {
        startPage();
        List<PlanClassification> list = planClassificationService.selectPlanClassificationList(planClassification);
        return getDataTable(list);
    }

    /**
     * 导出方案库分类列表
     */
    @PreAuthorize("@ss.hasPermi('decision:planclassification:export')")
    @Log(title = "方案库分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PlanClassification planClassification)
    {
        List<PlanClassification> list = planClassificationService.selectPlanClassificationList(planClassification);
        ExcelUtil<PlanClassification> util = new ExcelUtil<PlanClassification>(PlanClassification.class);
        util.exportExcel(response, list, "方案库分类数据");
    }

    /**
     * 获取方案库分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('decision:planclassification:query')")
    @GetMapping(value = "/{templateTypeId}")
    public AjaxResult getInfo(@PathVariable("templateTypeId") String templateTypeId)
    {
        return AjaxResult.success(planClassificationService.selectPlanClassificationByTemplateTypeId(templateTypeId));
    }

    /**
     * 新增方案库分类
     */
    @PreAuthorize("@ss.hasPermi('decision:planclassification:add')")
    @Log(title = "方案库分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PlanClassification planClassification)
    {
        return toAjax(planClassificationService.insertPlanClassification(planClassification));
    }

    /**
     * 修改方案库分类
     */
    @PreAuthorize("@ss.hasPermi('decision:planclassification:edit')")
    @Log(title = "方案库分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PlanClassification planClassification)
    {
        return toAjax(planClassificationService.updatePlanClassification(planClassification));
    }

    /**
     * 删除方案库分类
     */
    @PreAuthorize("@ss.hasPermi('decision:planclassification:remove')")
    @Log(title = "方案库分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{templateTypeIds}")
    public AjaxResult remove(@PathVariable String[] templateTypeIds)
    {
        return toAjax(planClassificationService.deletePlanClassificationByTemplateTypeIds(templateTypeIds));
    }
}
